
	** Clean Niger Wave 1
	
	** Merge datasets
		
		use "$dir/rawdata/EHCVM Niger/2011/ecvmaind_p1p2_en.dta", clear // roster
			isid hid ms01q00
			ren ms01q00 indiv // renaming individual id to indiv for consistency with other countries
			gen menage_str=string(menage)
			replace menage_str="00"+menage_str if strlen(menage_str)==1
			replace menage_str="0"+menage_str if strlen(menage_str)==2
			gen grappe_str=string(grappe)
			gen hhid=grappe_str+menage_str
			
			isid hhid indiv

			tempfile roster
			save `roster', replace
		
		use "$dir/rawdata/EHCVM Niger/2011/ecvmasection00_p1_en.dta", clear // hh identification section
			gen menage_str=string(menage)
			replace menage_str="00"+menage_str if strlen(menage_str)==1
			replace menage_str="0"+menage_str if strlen(menage_str)==2
			gen grappe_str=string(grappe)
			gen hhid=grappe_str+menage_str
			isid hhid
			tempfile sector
			save `sector', replace
			
			use `roster', clear
			merge m:1 hhid using `sector', gen(merge_sector) assert(matched) keepusing(ms00q15)
			
		***********
		***********	
	
		** Household size
			gen w1_inhh=ms00qc==1
			bys hhid: egen w1_hh_size=total(w1_inhh)
			
		** Marital status
			gen w1_married=(ms01q15==2 | ms01q15==3) if !missing(ms01q15) & ms01q15 != 9 // 9 is don't know; treated as missing

		** Female
			gen w1_female=(ms01q01==2) if !missing(ms01q01)

		** Age
			gen w1_age=ms01q06a 
			replace w1_age = ms01q06a + ms01q06b/12 if  ms01q06b ! = . // age in years from age in year and month
		
		** Urban status
			gen w1_urban=ms00q15!=3 if !missing(ms00q15)
			
		***********
		***********
		
		** Any work
			// Note - this wave only asks about employment in the last 30 days and 12 months
			** In last 30 days, any work in agriculture
				gen w1_work_agHH=(ms04q03==1) if !missing(ms04q03)
				
			** In last 30 days, any work in some kind of trade or salaried employment (for household or otherwise)
				gen w1_work_bizHHother=(ms04q05==1) if !missing(ms04q05)
				
			** In last 30 days, any work outside the HH
				gen w1_work_outsideHH=(ms04q01==1 | ms04q07==1) if !missing(ms04q01) | !missing(ms04q07)
				
			** Apprenticeshops: ms04q09: Not including
				
			** Any work in last 30 days (agriculture, for non-HH member, own account/business)
				gen w1_worked_last30days=0
				replace w1_worked_last30days=1 if ms04q01==1
				replace w1_worked_last30days=1 if ms04q03==1 
				replace w1_worked_last30days=1 if ms04q05==1
				replace w1_worked_last30days=1 if ms04q07==1
				replace w1_worked_last30days=. if missing(ms04q01) & missing(ms04q03) & missing(ms04q05) & missing(ms04q07)
						
		** Work hours
			
			** Usual months per year
				gen w1_worked_monthsperyear=ms04q29
				
			** Usual days per month
				*gen w1_worked_dayspermonth=ms04q31 * (30/7) if ms04q31!=9 // this wave has days per week, multiply by 4 to get days per month
				*replace w1_worked_dayspermonth=0 if w1_worked_last30days==0 // not enforcing since about work over last year, not last 30 days
				
			** Usual days per week
				gen w1_worked_daysperweek=ms04q31 if ms04q31!=9
				*replace w1_worked_daysperweek=0 if w1_worked_last30days==0 // not enforcing
				
			** Usual hours per day
				gen w1_worked_hoursperday=ms04q30
				*replace w1_worked_hoursperday=0 if w1_worked_last30days==0 // not enforcing
				
			** Weekly hours
				gen w1_work_hrs=((w1_worked_monthsperyear/12) * w1_worked_daysperweek * w1_worked_hoursperday) // interpretation is typical weekly hours
				*gen w1_work_hrs=(w1_worked_dayspermonth*w1_worked_hoursperday)/(30/7)
				
		***********
		***********
		
		** Any illness or injury during the last 30 days
			gen w1_illinj=(ms03q01==1) if !missing(ms03q01) & ms03q01 != 9

		** Had to stop usual activity in the past 4 weeks
			gen w1_illinj_stopactivity=(ms03q03==1) if !missing(ms03q03) & ms03q03 != 9
			replace w1_illinj_stopactivity=0 if w1_illinj==0
			
		***********
		***********
		
		** Depression
		
			** N/A
			
		***********
		***********
		
		** Functional limitations
		
			** N/A
			
		***********
		***********
		
		ren grappe w1_grappe 
		
		keep hhid indiv w1*
		order hhid indiv w1*
		save "$dir/data/niger_w1_individual.dta", replace
